package mapDemo;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class Demo4 {
	public static void main(String[] args){
		String str = "努力进取，拼命学java,然后赚大钱！";
		Map<Character, Integer> map = count(str);
		System.out.println(map);
		Collection collection = map.values();
		Iterator<Integer> iterator = collection.iterator();
		int sum=0;
		while(iterator.hasNext()){
			int a = iterator.next();
			sum+=1;
		}
		
		Set<Character> set=map.keySet();
		Iterator<Character> iterator2 = set.iterator();
		while(iterator2.hasNext()){
			char c = iterator2.next();  //key
			int num = map.get(c); //value
			//System.out.println(c+"\t"+num+"\t"+(double)num/sum*100);
			System.out.println(c+"\t"+num+"\t"+(double)num/str.length()*100);			
		}
		
		System.out.println(sum);
		System.out.println(collection.size());
	}
	
	public static Map<Character, Integer> count(String s){
		Map<Character, Integer> map = new HashMap<Character, Integer>();
		for(int i=0;i<s.length();i++){
			char c = s.charAt(i);
			Integer num = map.get(c);
			System.out.println(num);
			num= num==null?1:num+1;
			map.put(c, num);
		}
		return map;
	}
}
